<?php
class SF_Translationinterface_TranslasController extends  Mage_Core_Controller_front_Action{

    public function gettranslasubmitAction(){
        $json = $this->getRequest()->getPost('json');

        if($json){
            $storeId   = '2';
            $approval  = '2';
            $status    = '1';
            try {
                $products = json_decode($json,true);
                foreach ($products as $item) {
                    $data = array();
                    $_product = Mage::getModel('catalog/product')->setStoreId($storeId)->loadByAttribute('sku',$item['sku']);
                    if(empty($_product)) continue;

                    $productId = $_product->getId();
                    $data['name'] = $item['title'];
                    $data['description'] = $item['longDescription'];
                    $data['short_description'] = $item['shortDescription'];

                    Mage::getSingleton('catalog/product_action')
                    ->updateAttributes(array($productId), $data, $storeId);

                    $this->getcommodityinformation($productId);
                    $jsonrun['productSku'][]=$item['sku'];
                }
                $jsonrun['status'] =  'success';

            }catch (Exception $e) {
                $jsonrun['status'] =  'error';
                Mage::log('Translation failure : '.$e->getMessage());
            }
        }else{
            $jsonrun['status'] = 'error';
             Mage::log('Translation data : '.'提交数据不存在');
        }
        Mage::log('Translation data : '.json_encode($jsonrun));
        echo json_encode($jsonrun);
    }
    /*
     *
     * 商品审核信息保存
     */
    public function getcommodityinformation($productId){
        $productIds = array();
        $configurable_ids = Mage::getModel('catalog/product_type_configurable')->getChildrenIds($productId);
        foreach($configurable_ids as $Ids){
            foreach($Ids as $pId){
                $productIds[]=$pId;
            }
        }
        $productIds[] = $productId;

        $storeId   = '0';
        $approval  = '2';
        $status    = '1';
        if (empty($productIds)) return false;
        try {
            Mage::getSingleton('catalog/product_action')
                ->updateAttributes(
                    $productIds,
                    array('approval' => $approval,'status'=>$status),
                    $storeId
                );
        }catch (Exception $e) {
            return false;
        }
        return true;
    }
}